<%-- 
    Document   : index
    Created on : Jul 9, 2011, 10:23:26 AM
    Author     : DangDucThinh
    UpdateDate   2011-07-21
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="ProjectMgtSystem.Entities.Task" %>
<%@page import="ProjectMgtSystem.Entities.Engineer" %>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@taglib  uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="Content-Style-Type" content="text/css" />
        <link href="css/style1.css" rel="stylesheet" type="text/css" />
        <link href="css/layout.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
        <!--Start Hien 07/25/2011: fix show error-->
        <script>
            $(document).ready(function(){
                show_error("<%= request.getAttribute("errorMessage").toString()%>");                 
            });
        </script>
        <!--End Hien 07/25/2011: fix show error-->
    </head>
    <script type="text/javascript">
        $(document).ready(function(){
            $(".insBtt").click(function(){
                $(".insert").toggle();
            });
        });
    </script>

    <script type="text/javascript">
        function show_confirm()
        {
            if(confirm("Are your sure?")){
                //                                         window.location("engineer.do?method=Delete");
            }
            else
                return false;
        }
    </script>

    <!--Start Hien 07/25/2011: fix show error-->
    <script type="text/javascript">
        function show_error(val)
        {    
            if(val != "null"){
                var msgErr = val;            
                if(msgErr != "" && msgErr!="1"){
                    /*if(msgEr.toString().indexOf("Insert_", 1))
                {
                    $(".insert").toggle(true);                                                
                    msgErr = msgErr.toString().substringData(8, msgEr.toString().length - 7);
                }*/
                    if(msgErr != "-1") {
                        alert(msgErr);
                    }
                    else{
                        alert("Data error!!!")
                    }                
                }                                    
                else
                    return false;
            }
            else{
                return false;
            }
        }  
    
        function validateForm()
        {
            var x= $("#TID").val();              
            var y= $("#Name").val();             
            var msgErr ="";
            if (x==null || x=="")
            {
                msgErr = "Task ID must be filled out.";                
            }
            if (y==null || y=="")
            {
                msgErr = msgErr + "\nTask Name must be filled out.";                
            }   
            if(msgErr != ""){
                alert(msgErr);
                return false;
            }                
        }
    </script>
    <!--End Hien 07/25/2011: fix show error--> 
    <body id="page1">
        <!-- header -->
        <div class="inner_copy"></div> 
        <div id="header">
            <div class="container">
                <!-- .logo -->
                <div class="logo">
                    <a href="index.html"><img src="images/logo1.jpg" alt="" /></a>
                </div>
                <!-- /.logo -->
                <!-- .nav -->
                <ul class="nav">
                    <li><a href="AdminHomepage.jsp">HOME</a></li>
                    <li><html:link href="engineer.do?method=View">ENGINEER</html:link></li>
                    <li><html:link href="ProjectAction.do?method=View">PROJECT</html:link></li>
                    <li><a href="#" class="current">TASK</a></li>    
                </ul>
                <!-- /.nav -->
                <form action="" id="search-form">
                    <fieldset>
                        <p>Back to <a href="login.jsp">log in</a> page.</p>
                    </fieldset>
                </form>

            </div>
        </div>
        <!-- content -->
        <div id="content">
            <div class="container">
                <div class="inside">
                    <div class="wrapper">
                        <!--left category-->

                        <!--end left category -->
                        <div class="mainContent">

                            <!------------------------------------------------------------------------------------------------------->                            
                            <!----------------------------- Our main content begins here -------------------------------------------->
                            <!------------------------------------------------------------------------------------------------------->
                            <div class="add"><button class="insBtt">Add New Task</button></div>
                            <div class="insert">
                                <table>
                                    <html:form method="doGET" action="/TaskAction">
                                        <tr>
                                            <th scope="col">Task ID</th>
                                            <td><html:text property="taskID" styleId="TID"/></td>
                                        </tr> 
                                        <tr>
                                            <th scope="col">Task Name</th>
                                            <td><html:text property="taskName" styleId="Name"/></td>
                                        </tr>    
                                        <tr>
                                            <th scope="col">Description</th>                                            
                                            <td><html:textarea property="description"/></td>
                                        </tr> 
                                        <tr>
                                            <td><html:submit property="method" onclick="return validateForm()"><bean:message key="TaskAction.insert"/></html:submit></td>
                                        </tr>
                                    </html:form>
                                </table>
                            </div>
                            <table id="mytable" cellspacing="0">
                                <tr>
                                    <th scope="col">Task ID</th>
                                    <th scope="col">Task Name</th>
                                    <th scope="col">Description</th>
                                    <%
                                        java.util.ArrayList<Task> taskList = (java.util.ArrayList<Task>) request.getAttribute("taskList");
                                        for (Task task : taskList) {%>
                                    <html:form action="/TaskAction">
                                        <tr>
                                            <%
                                                out.print("<td>" + task.getTaskID() + "</td>");
                                                out.print("<td>" + task.getTaskName() + "</td>");
                                                out.print("<td>" + task.getDescription() + "</td>");
                                            %>
                                            <html:hidden property="taskID" value="<%=task.getTaskID()%>"/>
                                            <td><html:submit property="method" onclick="return show_confirm()"><bean:message key="TaskAction.delete"/></html:submit></td>
                                            <td><html:submit property="method"><bean:message key="TaskAction.select"/></html:submit></td>
                                            <%
                                                out.print("</tr>");
                                            %>
                                        </html:form>   
                                        <%
                                            }
                                        %>
                                    </tr>
                            </table>

                            <!-----------------------------End main content-------------------------------------------------------------->

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- footer -->
        <div id="footer">
            <div class="container">
                <div class="inside">
      	Copyright &copy; Team A POSCO-ICT
                </div>
            </div>
        </div>
    </body>
</html>
